package servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RegistrationServlet extends HttpServlet 
{
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException 
	{
		doProcessing(req, resp);
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException 
	{
		doProcessing(req, resp);
	}
	
	private void doProcessing(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
	{
		String firstName = req.getParameter("firstName");
		String lastName = req.getParameter("lastName");
		String addressLine1 = req.getParameter("addressLine1");
		String addressLine2 = req.getParameter("addressLine2");
		String addressLine3 = req.getParameter("addressLine3");
		String postcode = req.getParameter("postcode");
		String birthDate = req.getParameter("birthDate");
		String emailAddress = req.getParameter("emailAddress");
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		
		req.getSession().setAttribute("firstName", firstName);
		req.getSession().setAttribute("lastName", lastName);
		req.getSession().setAttribute("addressLine1", addressLine1);
		req.getSession().setAttribute("addressLine2", addressLine2);
		req.getSession().setAttribute("addressLine3", addressLine3);
		req.getSession().setAttribute("postcode", postcode);
		req.getSession().setAttribute("birthDate", birthDate);
		req.getSession().setAttribute("emailAddress", emailAddress);
		req.getSession().setAttribute("username", username);
		req.getSession().setAttribute("password", password);
		
		// go back to the index.jsp
		RequestDispatcher dispatcher = req.getRequestDispatcher("register.jsp");
		dispatcher.forward(req, resp);
	}
}
